import 'package:bot_toast/bot_toast.dart';
import 'package:easy_read_comic/controller/app_controller.dart';
import 'package:easy_read_comic/controller/home_controller.dart';
import 'package:easy_read_comic/models/app_model.dart';
import 'package:easy_read_comic/view/book/bool_view.dart';
import 'package:easy_read_comic/view/index/index_view.dart';
import 'package:easy_read_comic/view/me/me_view.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class HomeView extends StatelessWidget {
  final List<Widget> body = [
    IndexView(),
    BookView(),
    MeView(),
  ];

  @override
  Widget build(BuildContext context) {
    if (AppController().IsReadTips == false) {
      BotToast.showSimpleNotification(
        title: "温馨提示",
        subTitle: "亲爱的用户您好,本站资源全部来源于第三方。如对您造成了影响。请您联系站长,站长将在24小时内删除!",
      );
      AppController().storeAppDataAndSyncCaller((AppModel app) {
        app.IsReadTips = true;
        return app;
      });
    }
    return GetBuilder<HomeController>(
      init: HomeController(),
      builder: (controller) {
        return Scaffold(
          appBar: PreferredSize(
            preferredSize: Size(0.0, 0.0),
            child: AppBar(
              backgroundColor: Theme.of(context).primaryColor,
            ),
          ),
          body: SafeArea(child: body[controller.currentBottomIndex]),
          bottomNavigationBar: BottomNavigationBar(
            currentIndex: controller.currentBottomIndex,
            onTap: (index) => controller.changeCurrentBottomIndex(index),
            selectedItemColor: Theme.of(context).primaryColor,
            items: [
              BottomNavigationBarItem(
                label: "首页",
                icon: Icon(
                  Icons.home,
                ),
              ),
              BottomNavigationBarItem(
                label: "书架",
                icon: Icon(
                  Icons.book,
                ),
              ),
              BottomNavigationBarItem(
                label: "我的",
                icon: Icon(
                  Icons.person,
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
